package demo2;

public class Test2 {
    public static void main(String[] args) {
        String s1 = "A man, a plan, a canal: Panama";
        String s = s1.toLowerCase();
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            //重点判断一下left < right
            while ((left < right) && !(isValidCharacters(s.charAt(left)))) {
                left++;
            }
            //重点判断一下left < right
            while ((left < right) && !(isValidCharacters(s.charAt(right)))) {
                right--;
            }
            if (!(s.charAt(left) == s.charAt(right))) {
                return; //return false
            } else {
                left++;
                right--;
            }
        }
        return;  //return true
    }
    public static boolean isValidCharacters(char ch) {
        return Character.isDigit(ch) || Character.isLetter(ch) ? true : false;
    }
}
